package com.qianxx.component.activity.tab.tab_pager_indicator;

import android.os.Bundle;
import android.support.v4.app.Fragment;
import android.support.v4.app.FragmentManager;
import android.support.v4.app.FragmentPagerAdapter;
import android.support.v4.view.ViewPager;

import com.qianxx.component.R;
import com.qianxx.component.activity.base.BaseActivity;
import com.qianxx.component.activity.tab.tab_layout.fragment.MyFragment;
import com.qianxx.viewlibrary.tab.tabpagerindicator.TabPageIndicator;

import butterknife.BindView;
import butterknife.ButterKnife;

public class TabPagerIndicatorActivity extends BaseActivity {
    @BindView(R.id.tab_page_Indicator)
    TabPageIndicator tab_page_Indicator;
    @BindView(R.id.view_pager)
    ViewPager view_pager;

    private TabAdapter adapter;
    public static String[] TITLES = new String[]{"国际", "国内", "财经", "体育",
            "军事", "科技"};

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_tab_pager_indicator);
        ButterKnife.bind(this);

        adapter = new TabAdapter(getSupportFragmentManager());
        view_pager.setAdapter(adapter);
        tab_page_Indicator.setViewPager(view_pager, 0);
    }

    class TabAdapter extends FragmentPagerAdapter {

        public TabAdapter(FragmentManager fm) {
            super(fm);
        }

        @Override
        public Fragment getItem(int arg0) {
            MyFragment fragment = MyFragment.newIntance(arg0);
            return fragment;
        }

        @Override
        public CharSequence getPageTitle(int position) {
            return TITLES[position % TITLES.length];
        }

        @Override
        public int getCount() {
            return TITLES.length;
        }

    }

    @Override
    public String setTitle() {
        return "TabPagerIndicator";
    }
}
